<template>
  <div>
    <div class="register-space"></div>
    <div class="register-bar flex v-align-c">
      <p class="flex-item">登录/注册成为主播后可见商品佣金</p>
      <div class="reg-btn flex flex-center" @click="regBtn">
        <span>立即注册</span>
      </div>
    </div>
    <!-- 主播申请状态 -->
    <identity-type v-if="anchorBoolean"></identity-type>    
  </div>
</template>

<script>
  import IdentityType from '@/components/identityType'
  import {getAnchorApplyList} from '@/api/personal'
  export default {
    components: { IdentityType },
    data() {
      return {
        anchorBoolean: false,
        promptText: '',
        platformObj: {},
        statusNum: null
      }
    },
    onLoad() {
      // 初始化data
      Object.assign(this.$data, this.$options.data())
    },
    onShow() {
      this.initEls()
    },
    mounted() {
      setTimeout(() => {
        this.initEls()
      }, 100)
    },
    methods: {
      initEls() {
        this.getAnchorApplyList()
        // this.regBtn()
      },
      getAnchorApplyList() {
        if (!this.getCustomerId) return
        this.statusNum = null
        let data = {
          memberId: this.getCustomerId
        }
        getAnchorApplyList(data).then((response) => {
          if (response.isError) return
          let resData = response.data
          if (resData.length) {
            this.statusNum = -1
            resData.forEach(item => {
              this.$set(this.platformObj, item['relationPlatform'], {})
              this.$set(this.platformObj[item['relationPlatform']], 'applyStatus', item['applyStatus'])
              this.$set(this.platformObj[item['relationPlatform']], 'rejectReason', item['rejectReason'])
              if (item.applyStatus === 1) {
                this.statusNum = 1
              }
            })
          }
        }).catch(() => {
        })
      },
      regBtn() {
        if (!this.getCustomerId) {
          this.$pt.hideTabBar({
            animation: false
          })
          if (!this.$pt.getStorageSync('roleType')) {
            this.$parent.userTypeBoolean = true
            return
          }
          this.$parent.isGetUserInfo = false
          setTimeout(() => {
            this.$parent.isGetUserInfo = true
          }, 100)
        } else {
          if (this.statusNum) {
            this.anchorBoolean = true
          } else {
            let loginCode = this.$pt.getStorageSync('loginCode')
            switch (loginCode) {
              case 1:
                // 主播身份
                this.$pt.navigateTo({ url: '/pages/personal/apply-anchor/main?inPage=1' })
                break
              case 2:
                // 中介
                this.$parent.userTypeBoolean = true
                this.$parent.hideTabBar()
                this.$parent.nextTickLoginEls()
                break
              case 5000:
                // 没登录过
                this.$parent.userTypeBoolean = true
                this.$parent.hideTabBar()
                break
              case 5001:
                // 账号密码错误
                this.$parent.userTypeBoolean = true
                this.$parent.hideTabBar()
                this.$parent.nextTickLoginEls()
                break
            }
          }
        }
      }
    }
  }
</script>

<style scoped lang="less">
</style>
